﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class UserControl_ControlListChemist : System.Web.UI.UserControl
{
    ClassExecute.ClassExecute dt;
    string str = webapp4U.Configuration.CurrentConnectionString;
    string error = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            GetTinhThanh();
            GetQuanHuyen();
        }
    }
    protected void btnXem_Click(object sender, EventArgs e)
    {
        BindGrid(DropProvince.SelectedValue.ToString(),DropTown.SelectedValue.ToString());
    }
    void BindGrid(string province, string Town)
    {
        try
        {
            GridView1.DataSource = null;
            dt = new ClassExecute.ClassExecute();
            DataTable db = dt.Get_Data_DataTable(str, ref error, "k_getChemmist", CommandType.StoredProcedure,
                new SqlParameter("@MaTinh", province),
                new SqlParameter("@MaQuan", Town));
            if (db.Rows.Count > 0)
            {
                GridView1.DataSource = db;

            }
            GridView1.DataBind();
        }
        catch
        {
            return;
        }
    }
    void GetTinhThanh()
    {
        dt = new ClassExecute.ClassExecute();
        DataTable db = dt.Get_Data_DataTable(str, ref error, "k_getTinhThanh", CommandType.StoredProcedure);
        dt.BindDropDownList(db, DropProvince, "MaTinh", "TinhThanh");
             
    }
    void GetQuanHuyen()
    {
        dt = new ClassExecute.ClassExecute();
        DataTable db = dt.Get_Data_DataTable(str, ref error, "k_getQuanHuyen", CommandType.StoredProcedure,
            new SqlParameter("@MaTinh",DropProvince.SelectedValue.ToString()));
        dt.BindDropDownList(db, DropTown, "MaQuan", "QuanHuyen");

    }
    protected void DropProvince_SelectedIndexChanged(object sender, EventArgs e)
    {
        GetQuanHuyen();
    }
}